<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
		<title>流程发布管理</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>

		<script>
//$.messager.defaults={ok:"确定",cancel:"取消"};   

$(function() {
	$('#lockList').datagrid( {
		title : '任务资源列表',
		url : "${ctx}/flow/task_url/flow-task-url!data.action?sysId=${sysId}",
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		//striped: true,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
		remoteSort : false,
		pageList : [ 15, 30, 50 ],
		idField : 'id',
		frozenColumns : [ [ {
			title : '任务名称',
			field : 'taskName',
			width : 200,
			formatter : function(value) {
				return '<span style="color:blue">' + value + '</span>';
			}
		} ] ],
		columns : [ [ {
			field : 'taskUrl',
			title : '任务路径',
			width : 220,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'taskType',
			title : '任务类型',
			width : 60,
			formatter : function(value) {
				return value=="1"?"人工处理任务":"自处理任务";
			}
		}, {
			field : 'createTime',
			title : '创建时间',
			width : 200
		}] ],

		toolbar : [ {
			text : '增加',
			iconCls : 'icon-add',
			handler : function() {
				addLock();
			}

		}, {
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				editLock();
			}
		}, '-', {
			text : '删除',
			iconCls : 'icon-cut',
			handler : function() {
				delLock();
			}
		}, '-',

		{
			text : '刷新',
			iconCls : 'icon-reload',
			handler : function() {
				reload('');
			}
		} ],
		onDblClickRow:function(row){
			editLock();
		}
	});
});

function delLock() {
	var node = getSelected();
	if (node) {
		$.messager.confirm('确认', '您确定要删除:<font color="red">' + node.taskName + '</font> ？',
				function(r) {
					if (r) {
						$.ajax( {
							type : "post",
							url : "${ctx}/flow/task_url/flow-task-url!delete.action?taskId="+ node.id,
									
							beforeSend : function(XMLHttpRequest) {
								//ShowLoading();
							},
							success : function(data, textStatus) {
								var result = jQuery.parseJSON(data);
								if(result.flag=="T"){
									$.messager.alert('结果', '操作成功', 'info');
									var rowIndex = $('#lockList').datagrid('getRowIndex', node);
									$('#lockList').datagrid('deleteRow', rowIndex);
								}else{
									$.messager.alert('结果',result.msg,'warning');
								}
								
							},
							complete : function(XMLHttpRequest, textStatus) {
								//HideLoading();
						},
						error : function() {
							//请求出错处理
						}
						});
					}
				});
	}

}

function editLock() {
	var node = getSelected();
	if (node) {
		$('#lockAddFrame').html('');
		var url = '${ctx}/flow/task_url/flow-task-url!toSave.action?taskId=' + node.id;
		$('#lockAddFrame').attr("src", url);
		$('#lockAddWin').window('open');
	}
}

function closeAddWin(){
	$('#lockAddWin').window('close');
}

function addLock() {
	$('#lockAddFrame').html('');
	var url = "${ctx}/flow/task_url/flow-task-url!toSave.action?sysId=${sysId}";
	$('#lockAddFrame').attr("src", url);
	$('#lockAddWin').window('open');
}

function getSelected() {
	var selected = $('#lockList').datagrid('getSelected');
	if (selected) {
		return selected;
	} else {
		$.messager.alert('提示', '请选择要操作的数据', 'info');
	}
}

function reload(){
	$('#lockList').datagrid('reload');
}
		
function lockQuery(){					
    var queryParams = $('#lockList').datagrid('options').queryParams;
     var opt = $('#lockList').datagrid('options'); 
     $('#lockList').datagrid('options').pageNumber=1;
      queryParams.taskName = $('#lockCname').val();
      queryParams.taskUrl = $('#lockPath').val();
      reload(); 
        var page = $('#lockList').datagrid('getPager');
	page.pagination({pageNumber:1,pageSize:opt.pageSize});
  }
function clearQuery(){					
    $('#lockCname').val('');
    $('#lockPath').val('');
    lockQuery(); 
 }  
	  
			
</script>
</head>

	<body>
		<table class="datagrid-body">
			<tr>
				<td class="datagrid-header">
					任务名称
				</td>
				<td>
					<input name="lockCname" id="lockCname" value=""/>
				</td>
				
				<td class="datagrid-header">
					任务路径
				</td>
				<td>
					<input name="lockPath" id=lockPath value=""/>
				</td>
				
				<td>
					<a class="easyui-linkbutton" iconCls="icon-search"
						onclick="lockQuery();">查询</a>
					<a class="easyui-linkbutton" iconCls="" onclick="clearQuery();">清空</a>
				</td>
			</tr>
		</table>


		<table id="lockList"></table>
		<center><a class="easyui-linkbutton" iconCls="" onclick="window.location.href='${ctx}/flow/task_url/flow-task-url.action'">返回</a></center>
		<div id="lockAddWin" class="easyui-window" title="资源信息"
			style="padding: 5px; width: 600px; height: 400;"
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false">
			<iframe frameborder="0" id="lockAddFrame" height="100%" width="100%"
				scrolling="yes" frameborder="0"></iframe>
		</div>

	</body>
</html>